
package org.come.Jpanel;

import com.tool.btn.DazaoBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.goodbtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.math.BigDecimal;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.mouslisten.TransmuteMouslisten;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.Util;

 

public class ForgeJpanel extends JPanel {
    private BigDecimal money1 = new BigDecimal(100000);
    private DazaoBtn btndazao;
    private JList<String> listEquipment;
    private DefaultListModel<String> modelTrade;
    private DefaultListModel<String> modelname;
    private Color fontcolor;
    private JLabel[] topTitle;
    private ImageIcon jiemianimg;
    private JLabel[] GoodsListLabel = new JLabel[26];
    private String type = "我要炼器";
    private boolean shoptext = false;
    private int goodPosition;
    private TransmuteMouslisten[] transmuteMouslistens = new TransmuteMouslisten[26];
    private goodbtn[] btnrights;
    private int Flag = 0;
    private int count = 1;

    public ForgeJpanel() throws Exception {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
    		// 键盘监听
            this.setPreferredSize(new Dimension(400, 400));
            this.setLayout(null);
            this.setOpaque(false);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 26);
            offBtn.setBounds(400 - 37, 10, 25, 25);
            this.add(offBtn);

            btnrights = new goodbtn[6];
            for (int i = 0; i < btnrights.length; i++) {
                btnrights[i] = new goodbtn("skin/8100226/newbutton/C0"+(i+1)+".png", 0, this, i);
                btnrights[i].setBounds(353, 174 + i * 35, 35, 31);
                this.add(btnrights[i]);
            }
            // 操作栏上的字
            topTitle = new JLabel[2];
            for (int i = 0; i < topTitle.length; i++) {
                topTitle[i] = new JLabel();
                topTitle[i].setBounds(93 + i * 134, 15, 56 + i * 34, 20);
                topTitle[i].setHorizontalAlignment(SwingConstants.CENTER);
                topTitle[i].setFont(UIUtils.TEXT_FONT1);
                // topTitle[i].setOpaque(true);
                topTitle[i].setForeground(Color.white);
                topTitle[i].setText("1阶仙器");
                this.add(topTitle[i]);
            }
            // 存放物品的表格1~26
            for (int i = 0; i < 26; i++) {

                GoodsListLabel[i] = new JLabel();
                transmuteMouslistens[i] = new TransmuteMouslisten(i, this);
                GoodsListLabel[i].addMouseListener(transmuteMouslistens[i]);
                if (i < 24) {
                    GoodsListLabel[i].setBounds(16 + 28 + i % 6 * 51, 175 + i / 6 * 51, 48, 48);
                    this.add(GoodsListLabel[i]);
                } else {
                    GoodsListLabel[i].setBounds(96 + i % 6 * 150, 40, 55, 51);
                    this.add(GoodsListLabel[i]);
                }
            }

            btndazao = new DazaoBtn("skin/8100226/newbutton/B21.png", 1, UIUtils.COLOR_WHITE2, "打造", UIUtils.TEXT_HY16, this);
            btndazao.setBounds(266, 123, 79, 24);
            this.add(btndazao);
        } else {
            //
            this.setPreferredSize(new Dimension(360, 386));
            this.setLayout(null);
            this.setOpaque(false);
            FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 26);
            offBtn.setBounds(340, 0, 23, 23);
            this.add(offBtn);
            btnrights = new goodbtn[6];

            int i;
            for(i = 0; i < this.btnrights.length; ++i) {
                this.btnrights[i] = new goodbtn("inkImg/hongmu/SBG.png", 0, this, i);
                this.btnrights[i].setBounds(326, 151 + i * 33, 24, 33);
                this.add(this.btnrights[i]);
            }

            this.topTitle = new JLabel[2];

            for(i = 0; i < this.topTitle.length; ++i) {
                this.topTitle[i] = new JLabel();
                //this.topTitle[i].setBounds(44 + i * 59, 38, 56 + i * 34, 20);
                this.topTitle[i].setHorizontalAlignment(0);
                this.topTitle[i].setFont(UIUtils.TEXT_FONT1);
                this.topTitle[i].setForeground(Color.white);
                this.topTitle[i].setText("1阶仙器");
                this.add(this.topTitle[i]);
            }

            for(i = 0; i < 26; ++i) {
                this.GoodsListLabel[i] = new JLabel();
                this.transmuteMouslistens[i] = new TransmuteMouslisten(i, this);
                this.GoodsListLabel[i].addMouseListener(this.transmuteMouslistens[i]);
                if (this.Flag < 6 && this.count == 1) {
                    this.GoodsListLabel[i].setBounds(19 + this.Flag * 51, 153, 49, 49);
                    ++this.Flag;
                    this.add(this.GoodsListLabel[i]);
                }

                if (this.Flag < 6 && this.count == 2) {
                    this.GoodsListLabel[i].setBounds(19 + this.Flag * 51, 205, 49, 49);
                    ++this.Flag;
                    this.add(this.GoodsListLabel[i]);
                }

                if (this.Flag < 6 && this.count == 3) {
                    this.GoodsListLabel[i].setBounds(19 + this.Flag * 51, 257, 49, 49);
                    ++this.Flag;
                    this.add(this.GoodsListLabel[i]);
                }

                if (this.Flag < 6 && this.count == 4) {
                    this.GoodsListLabel[i].setBounds(19 + this.Flag * 51, 309, 49, 49);
                    ++this.Flag;
                    this.add(this.GoodsListLabel[i]);
                }

                if (this.Flag < 2 && this.count == 5) {
                    this.GoodsListLabel[i].setBounds(43 + this.Flag * 93, 61, 65, 65);
                    ++this.Flag;
                    this.add(this.GoodsListLabel[i]);
                } else if (this.Flag == 6) {
                    this.Flag = 0;
                    ++this.count;
                }
            }

            this.btndazao = new DazaoBtn("inkImg/hoNGMU/1_png.button.btn_xy.png", 1, UIUtils.COLOR_BTNPUTONG2, "打造", UIUtils.TEXT_HY88, this);
            this.btndazao.setBounds(246, 123, 80, 24);
            this.add(this.btndazao);
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        	// 打造
            if (jiemianimg == null) {
                jiemianimg = new ImageIcon("inkImg/newbackground/B261.png");
            }
            g.drawImage(jiemianimg.getImage(), 0, 0, 400, 400, this);

            if (shoptext) {
                // 判断属于几行几列
                int shop_x = goodPosition % 6;
                int shop_y = goodPosition / 6;
                g.setColor(Color.red);
                g.drawLine(16 + 31 + shop_x * 51, 175 + shop_y * 51, 64 + 31 + shop_x * 51, 175 + shop_y * 51);// 左上横线
                g.drawLine(16 + 31 + shop_x * 51, 175 + shop_y * 51, 16 + 31 + shop_x * 51, 223 + shop_y * 51);// 左上竖线
                g.drawLine(64 + 31 + shop_x * 51, 176 + shop_y * 51, 64 + 31 + shop_x * 51, 223 + shop_y * 51);// 右下横线
                g.drawLine(16 + 31 + shop_x * 51, 223 + shop_y * 51, 64 + 31 + shop_x * 51, 223 + shop_y * 51);// 右下竖线
            }
            Util.drawMoney(g, 92 + 12, 132 - 4);
            Util.drawPrice(g, money1, 92 + 12, 166 - 4);

            GoodsListFromServerUntil.draw(g, 16 + 28, 175 - 1);
        } else {
            //
            if (this.jiemianimg == null) {
                this.jiemianimg = new ImageIcon("img/xy2uiimg/108_png.xy2uiimg.equip.png");
            }

            g.drawImage(this.jiemianimg.getImage(), 0, 0, 360, 386, this);
            if (this.shoptext) {
                int shop_x = this.goodPosition % 6;
                int shop_y = this.goodPosition / 6;
                g.setColor(Color.red);
                g.drawLine(20 + shop_x * 51, 154 + shop_y * 51, 67 + shop_x * 51, 154 + shop_y * 51);
                g.drawLine(20 + shop_x * 51, 154 + shop_y * 51, 20 + shop_x * 51, 201 + shop_y * 51);
                g.drawLine(67 + shop_x * 51, 154 + shop_y * 51, 67 + shop_x * 51, 201 + shop_y * 51);
                g.drawLine(20 + shop_x * 51, 201 + shop_y * 51, 67 + shop_x * 51, 201 + shop_y * 51);
            }


            Util.drawMoney(g, 239, 104);
            Util.drawPrice(g, this.money1, 239, 63);
            GoodsListFromServerUntil.draw(g, 19, 153);
        }
    }

    public void PaintingText(int goodPosition) {
        this.goodPosition = goodPosition;
        this.shoptext = true;
    }

    public void ClearText() {
        this.shoptext = false;
    }

    public void remove() {
        TransmuteMouslisten.goods2[0] = null;
        TransmuteMouslisten.goods2[1] = null;
        this.GoodsListLabel[24].setIcon(null);
        this.GoodsListLabel[25].setIcon(null);
    }

    public JList<String> getListEquipment() {
        return this.listEquipment;
    }

    public void setListEquipment(JList<String> listEquipment) {
        this.listEquipment = listEquipment;
    }

    public DefaultListModel<String> getModelTrade() {
        return this.modelTrade;
    }

    public void setModelTrade(DefaultListModel<String> modelTrade) {
        this.modelTrade = modelTrade;
    }

    public DefaultListModel<String> getModelname() {
        return this.modelname;
    }

    public void setModelname(DefaultListModel<String> modelname) {
        this.modelname = modelname;
    }

    public Color getFontcolor() {
        return this.fontcolor;
    }

    public void setFontcolor(Color fontcolor) {
        this.fontcolor = fontcolor;
    }

    public JLabel[] getGoodsListLabel() {
        return this.GoodsListLabel;
    }

    public void setGoodsListLabel(JLabel[] goodsListLabel) {
        this.GoodsListLabel = goodsListLabel;
    }

    public int getFlag() {
        return this.Flag;
    }

    public void setFlag(int flag) {
        this.Flag = flag;
    }

    public int getCount() {
        return this.count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public boolean isShoptext() {
        return this.shoptext;
    }

    public void setShoptext(boolean shoptext) {
        this.shoptext = shoptext;
    }

    public int getGoodPosition() {
        return this.goodPosition;
    }

    public void setGoodPosition(int goodPosition) {
        this.goodPosition = goodPosition;
    }

    public TransmuteMouslisten[] getTransmuteMouslistens() {
        return this.transmuteMouslistens;
    }

    public void setTransmuteMouslistens(TransmuteMouslisten[] transmuteMouslistens) {
        this.transmuteMouslistens = transmuteMouslistens;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public DazaoBtn getBtndazao() {
        return this.btndazao;
    }

    public void setBtndazao(DazaoBtn btndazao) {
        this.btndazao = btndazao;
    }

    public ImageIcon getJiemianimg() {
        return this.jiemianimg;
    }

    public void setJiemianimg(ImageIcon jiemianimg) {
        this.jiemianimg = jiemianimg;
    }

    public goodbtn[] getBtnrights() {
        return this.btnrights;
    }

    public void setBtnrights(goodbtn[] btnrights) {
        this.btnrights = btnrights;
    }

    public BigDecimal getMoney1() {
        return this.money1;
    }

    public void setMoney1(BigDecimal money1) {
        this.money1 = money1;
    }

    public JLabel[] getTopTitle() {
        return this.topTitle;
    }

    public void setTopTitle(JLabel[] topTitle) {
        this.topTitle = topTitle;
    }
}
